package com.xd.alibabanacosfeignserver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;


@EnableFeignClients
@RestController
@EnableDiscoveryClient
@SpringBootApplication
public class AlibabaNacosFeignServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(AlibabaNacosFeignServerApplication.class, args);
    }

    /**
     * 使用Feign调用
     */
    @FeignClient("provider-service")
    interface Client {
        @GetMapping("/echo/{name}")
        String hello(@PathVariable(name = "name") String name);
    }

    /**
     * 定义feign客户端
     */
    @Autowired
    private Client client;


    // 调用
    @GetMapping("/test")
    public String test() {
        String result = client.hello("lhd");
        return "Return : " + result;
    }
}
